﻿////using System;
////using System.Collections.Generic;
////using System.Linq;
////using System.Text;
////using System.Net.Sockets;
////using System.Net;
////using System.Text.RegularExpressions;
////using System.IO;

////namespace Framework.Common.Util
////{
////    /// <summary>
////    /// 
////    /// </summary>
////    public class SocketCrawlerHelper
////    {
////        /// <summary>
////        /// 发出请求并获取响应
////        /// </summary>
////        /// <param name="host"></param>
////        /// <param name="port"></param>
////        /// <param name="body"></param>
////        /// <param name="encode"></param>
////        /// <returns></returns>
////        private static string GetResponse(string host, int port, string body, Encoding encode)
////        {
////            string strResult = string.Empty;
////            byte[] bteSend = Encoding.ASCII.GetBytes(body);
////            byte[] bteReceive = new byte[1024];
////            int intLen = 0;

////            using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
////            {
////                try
////                {
////                    socket.Connect(host, port);
////                    if (socket.Connected)
////                    {
////                        socket.Send(bteSend, bteSend.Length, 0);
////                        while ((intLen = socket.Receive(bteReceive, bteReceive.Length, 0)) > 0)
////                        {
////                            strResult += encode.GetString(bteReceive, 0, intLen);
////                        }
////                    }
////                    socket.Close();
////                }
////                catch { }
////            }

////            return strResult;
////        }

////        /// <summary>
////        /// GET请求
////        /// </summary>
////        /// <param name="url"></param>
////        /// <param name="encode"></param>
////        /// <returns></returns>
////        public static string Get(string url, Encoding encode)
////        {
////            UrlInfo urlInfo = ParseURL(url);
////            string strRequest = string.Format("GET {0}?{1} HTTP/1.1\r\nHost:{2}:{3}\r\nConnection:Close\r\n\r\n", urlInfo.File, urlInfo.Body, urlInfo.Host, urlInfo.Port.ToString());
////            return GetResponse(urlInfo.Host, urlInfo.Port, strRequest, encode);
////        }

////        /// <summary>
////        /// POST请求
////        /// </summary>
////        /// <param name="url"></param>
////        /// <param name="encode"></param>
////        /// <returns></returns>
////        public static string Post(string url, Encoding encode)
////        {
////            UrlInfo urlInfo = ParseURL(url);
////            string strRequest = string.Format("POST {0} HTTP/1.1\r\nHost:{1}:{2}\r\nContent-Length:{3}\r\nContent-Type:application/x-www-form-urlencoded\r\nConnection:Close\r\n\r\n{4}", urlInfo.File, urlInfo.Host, urlInfo.Port.ToString(), urlInfo.Body.Length, urlInfo.Body);
////            return GetResponse(urlInfo.Host, urlInfo.Port, strRequest, encode);
////        }

////         /// <summary>
////        /// 获取内容
////        /// </summary>
////        /// <param name="rp">RequestParameter</param>
////        /// <returns></returns>
////        public static bool GetHtml(RequestParameter rp)
////        {
////            Uri uri = new Uri(rp.Url);
////        }
////    }

////    /// <summary>
////    /// 
////    /// </summary>
////    public class MyWebRequest
////    {
////        public MyWebRequest(Uri uri, bool bKeepAlive)
////        {
////            Headers = new WebHeaderCollection();
////            RequestUri = uri;
////            Headers["Host"] = uri.Host;
////            KeepAlive = bKeepAlive;
////            if (KeepAlive)
////                Headers["Connection"] = "Keep-Alive";
////            Method = "GET";
////        }
////        public static MyWebRequest Create(Uri uri, MyWebRequest AliveRequest, bool bKeepAlive)
////        {
////            if (bKeepAlive &&
////                AliveRequest != null &&
////                AliveRequest.response != null &&
////                AliveRequest.response.KeepAlive &&
////                AliveRequest.response.socket.Connected &&
////                AliveRequest.RequestUri.Host == uri.Host)
////            {
////                AliveRequest.RequestUri = uri;
////                return AliveRequest;
////            }
////            return new MyWebRequest(uri, bKeepAlive);
////        }
////        public MyWebResponse GetResponse()
////        {
////            if (response == null || response.socket == null || response.socket.Connected == false)
////            {
////                response = new MyWebResponse();
////                response.Connect(this);
////                response.SetTimeout(Timeout);
////            }
////            response.SendRequest(this);
////            response.ReceiveHeader();
////            return response;
////        }

////        public int Timeout;
////        public WebHeaderCollection Headers;
////        public string Header;
////        public Uri RequestUri;
////        public string Method;
////        public MyWebResponse response;
////        public bool KeepAlive;
////    }

////    /// <summary>
////    /// 
////    /// </summary>
////    public class MyWebResponse
////    {
////        /// <summary>
////        /// 
////        /// </summary>
////        /// <param name="request"></param>
////        public void Connect(MyWebRequest request)
////        {
////            ResponseUri = request.RequestUri;

////            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
////            IPEndPoint remoteEP = new IPEndPoint(Dns.Resolve(ResponseUri.Host).AddressList[0], ResponseUri.Port);
////            socket.Connect(remoteEP);
////        }
////        /// <summary>
////        /// 
////        /// </summary>
////        /// <param name="request"></param>
////        public void SendRequest(MyWebRequest request)
////        {
////            ResponseUri = request.RequestUri;

////            request.Header = request.Method + " " + ResponseUri.PathAndQuery + " HTTP/1.0\r\n" + request.Headers;
////            socket.Send(Encoding.ASCII.GetBytes(request.Header));
////        }

////        /// <summary>
////        /// 
////        /// </summary>
////        /// <param name="Timeout"></param>
////        public void SetTimeout(int Timeout)
////        {
////            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, Timeout * 1000);
////            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, Timeout * 1000);
////        }

////        /// <summary>
////        /// 
////        /// </summary>
////        public void ReceiveHeader()
////        {
////            Header = string.Empty;
////            Headers = new WebHeaderCollection();

////            byte[] bytes = new byte[10];
////            while (socket.Receive(bytes, 0, 1, SocketFlags.None) > 0)
////            {
////                Header += Encoding.ASCII.GetString(bytes, 0, 1);
////                if (bytes[0] == '\n' && Header.EndsWith("\r\n\r\n"))
////                    break;
////            }
////            MatchCollection matches = new Regex("[^\r\n]+").Matches(Header.TrimEnd('\r', '\n'));
////            for (int n = 1; n < matches.Count; n++)
////            {
////                string[] strItem = matches[n].Value.Split(new char[] { ':' }, 2);
////                if (strItem.Length > 0)
////                    Headers[strItem[0].Trim()] = strItem[1].Trim();
////            }
////            // check if the page should be transfered to another location
////            if (matches.Count > 0 && (
////                matches[0].Value.IndexOf(" 302 ") != -1 ||
////                matches[0].Value.IndexOf(" 301 ") != -1))
////                // check if the new location is sent in the "location" header
////                if (Headers["Location"] != null)
////                {
////                    try { ResponseUri = new Uri(Headers["Location"]); }
////                    catch { ResponseUri = new Uri(ResponseUri, Headers["Location"]); }
////                }
////            ContentType = Headers["Content-Type"];
////            if (Headers["Content-Length"] != null)
////                ContentLength = int.Parse(Headers["Content-Length"]);
////            KeepAlive = (Headers["Connection"] != null && Headers["Connection"].ToLower() == "keep-alive") ||
////                        (Headers["Proxy-Connection"] != null && Headers["Proxy-Connection"].ToLower() == "keep-alive");
////        }
////        public void Close()
////        {
////            socket.Close();
////        }
////        public Uri ResponseUri;
////        public string ContentType;
////        public int ContentLength;
////        public WebHeaderCollection Headers;
////        public string Header;
////        public Socket socket;
////        public bool KeepAlive;
////    }
////}


//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Diagnostics;
//using System.IO;
//using System.Net;
//using System.Net.Security;
//using System.Net.Sockets;
//using System.Security.Authentication;
//using System.Security.Cryptography.X509Certificates;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Threading;
//using System.Threading.Tasks;

//namespace Framework.Common
//{

//    public class HttpArgs
//    {

//        public string Url { get; set; }

//        public string Host { get; set; }

//        public string Accept { get; set; }

//        public string Referer { get; set; }

//        public string Cookie { get; set; }

//        public string Body { get; set; }

//    }



//    public static class SocketHttpHelper
//    {

//        /// <summary>

//        /// 提交方法

//        /// </summary>

//        enum HttpMethod
//        {

//            GET,

//            POST

//        }







//        #region Ssl Socket



//        static bool ValidateServerCertificate(

//                 object sender,

//                 X509Certificate certificate,

//                 X509Chain chain,

//                 SslPolicyErrors sslPolicyErrors)
//        {

//            /*

//            if (sslPolicyErrors == SslPolicyErrors.None)

//                return true;

//            Console.WriteLine("Certificate error: {0}", sslPolicyErrors);

//            return false;

//            */

//            return true;

//        }



//        public static byte[] Get(IPEndPoint endpoint, HttpArgs args, X509CertificateCollection certificates)
//        {

//            return InternalSslSocketHttp(endpoint, certificates, args, HttpMethod.GET);

//        }



//        public static byte[] Post(IPEndPoint endpoint,

//            HttpArgs args,

//            X509CertificateCollection certificates)
//        {

//            return InternalSslSocketHttp(endpoint, certificates, args, HttpMethod.POST);

//        }



//        static byte[] InternalSslSocketHttp(IPEndPoint endpoint,

//            X509CertificateCollection certificates,

//            HttpArgs args,

//            HttpMethod method)
//        {

//            TcpClient tcp = new TcpClient();

//            try
//            {

//                tcp.Connect(endpoint);

//                if (tcp.Connected)
//                {

//                    using (SslStream ssl = new SslStream(tcp.GetStream(),

//                        false,

//                        new RemoteCertificateValidationCallback(ValidateServerCertificate),

//                        null))
//                    {

//                        ssl.AuthenticateAsClient("ServerName",

//                            certificates,

//                            SslProtocols.Tls,

//                            false);

//                        if (ssl.IsAuthenticated)
//                        {

//                            byte[] buff = ParseHttpArgs(method, args);  //生成协议包

//                            ssl.Write(buff);

//                            ssl.Flush();

//                            return ParseSslResponse(endpoint, ssl, args, certificates);



//                        }

//                    }

//                }

//            }

//            catch (Exception ex)
//            {

//                Console.WriteLine(ex.Message);

//            }

//            return null;

//        }



//        /// <summary>

//        /// 解析 Ssl Response

//        /// </summary>

//        /// <param name="endpoint"></param>

//        /// <param name="ssl"></param>

//        /// <param name="args"></param>

//        /// <param name="certificates"></param>

//        /// <returns></returns>

//        private static byte[] ParseSslResponse(IPEndPoint endpoint,

//            SslStream ssl,

//            HttpArgs args,

//            X509CertificateCollection certificates)
//        {

//            //尝试10秒时间读取协议头

//            CancellationTokenSource source = new CancellationTokenSource();

//            Task<string> myTask = Task.Factory.StartNew<string>(

//                new Func<object, string>(ReadSslHeaderProcess),

//                ssl,

//                source.Token);

//            if (myTask.Wait(10000))
//            {

//                string header = myTask.Result;

//                if (header.StartsWith("HTTP/1.1 302"))
//                {

//                    int start = header

//                        .ToUpper().IndexOf("LOCATION");

//                    if (start > 0)
//                    {

//                        string temp = header.Substring(start, header.Length - start);

//                        string[] sArry = Regex.Split(temp, "\r\n");

//                        args.Url = sArry[0].Remove(0, 10);

//                        return Get(endpoint, args, certificates);  //注意：302协议需要重定向

//                    }

//                }

//                else if (header.StartsWith("HTTP/1.1 200"))  //继续读取内容
//                {

//                    int start = header

//                           .ToUpper().IndexOf("CONTENT-LENGTH");

//                    int content_length = 0;

//                    if (start > 0)
//                    {

//                        string temp = header.Substring(start, header.Length - start);

//                        string[] sArry = Regex.Split(temp, "\r\n");

//                        content_length = Convert.ToInt32(sArry[0].Split(':')[1]);

//                        if (content_length > 0)
//                        {

//                            byte[] bytes = new byte[content_length];

//                            if (ssl.Read(bytes, 0, bytes.Length) > 0)
//                            {

//                                return bytes;

//                            }

//                        }

//                    }

//                    else
//                    {

//                        //不存在Content-Length协议头

//                        return ParseSslResponse(ssl);

//                    }

//                }

//                else
//                {

//                    return Encoding.Default.GetBytes(header);

//                }

//            }

//            else
//            {

//                source.Cancel();  //超时的话，别忘记取消任务哦

//            }

//            return null;

//        }



//        /// <summary>

//        ///  读取协议头

//        /// </summary>

//        /// <param name="args"></param>

//        /// <returns></returns>

//        static string ReadSslHeaderProcess(object args)
//        {

//            SslStream ssl = (SslStream)args;

//            StringBuilder bulider = new StringBuilder();

//            while (true)
//            {

//                int read = ssl.ReadByte();

//                if (read != -1)
//                {

//                    byte b = (byte)read;

//                    bulider.Append((char)b);

//                }

//                string temp = bulider.ToString();

//                if (temp.Contains("\r\n\r\n"))
//                {

//                    break;

//                }

//            }

//            return bulider.ToString();

//        }



//        /// <summary>

//        /// 注意：此函数可能产生死循环

//        /// </summary>

//        /// <param name="ssl"></param>

//        /// <returns></returns>

//        static byte[] ParseSslResponse(SslStream ssl)
//        {

//            //没有指定协议头，尝试读取至</html>

//            ArrayList array = new ArrayList();

//            StringBuilder bulider = new StringBuilder();

//            int length = 0;

//            while (true)
//            {

//                byte[] buff = new byte[1024];

//                int len = ssl.Read(buff, 0, buff.Length);

//                if (len > 0)
//                {

//                    length += len;

//                    byte[] reads = new byte[len];

//                    Array.Copy(buff, 0, reads, 0, len);

//                    array.Add(reads);

//                    bulider.Append(Encoding.Default.GetString(reads));

//                }

//                string temp = bulider.ToString();

//                if (temp.ToUpper().Contains("</HTML>"))
//                {

//                    break;

//                }

//            }

//            byte[] bytes = new byte[length];

//            int index = 0;

//            for (int i = 0; i < array.Count; i++)
//            {

//                byte[] temp = (byte[])array[i];

//                Array.Copy(temp, 0, bytes,

//                    index, temp.Length);

//                index += temp.Length;

//            }

//            return bytes;

//        }



//        #endregion



//        #region Socket



//        public static byte[] Get(IPEndPoint endpoint,

//            HttpArgs args)
//        {

//            return InternalSocketHttp(endpoint, args, HttpMethod.GET);

//        }



//        public static byte[] Post(IPEndPoint endpoint,

//            HttpArgs args)
//        {

//            return InternalSocketHttp(endpoint, args, HttpMethod.POST);

//        }



//        static byte[] InternalSocketHttp(IPEndPoint endpoint,

//           HttpArgs args,

//           HttpMethod method)
//        {

//            using (Socket sK = new Socket(AddressFamily.InterNetwork,

//                        SocketType.Stream,

//                        ProtocolType.Tcp))
//            {

//                try
//                {

//                    sK.Connect(endpoint);

//                    if (sK.Connected)
//                    {

//                        byte[] buff = ParseHttpArgs(method, args);

//                        if (sK.Send(buff) > 0)
//                        {

//                            return ParseResponse(endpoint, sK, args);

//                        }

//                    }

//                }

//                catch (Exception ex)
//                {

//                    Console.WriteLine(ex.Message);

//                }

//            }

//            return null;

//        }



//        private static byte[] ParseResponse(IPEndPoint endpoint,

//             Socket sK,

//             HttpArgs args)
//        {

//            //尝试10秒时间读取协议头

//            CancellationTokenSource source = new CancellationTokenSource();

//            Task<string> myTask = Task.Factory.StartNew<string>(

//                new Func<object, string>(ReadHeaderProcess),

//                sK,

//                source.Token);

//            if (myTask.Wait(10000))
//            {

//                string header = myTask.Result;

//                if (header.StartsWith("HTTP/1.1 302"))
//                {

//                    int start = header

//                        .ToUpper().IndexOf("LOCATION");

//                    if (start > 0)
//                    {

//                        string temp = header.Substring(start, header.Length - start);

//                        string[] sArry = Regex.Split(temp, "\r\n");

//                        args.Url = sArry[0].Remove(0, 10);

//                        return Get(endpoint, args);  //注意：302协议需要重定向

//                    }

//                }

//                else if (header.StartsWith("HTTP/1.1 200"))  //继续读取内容
//                {

//                    int start = header

//                           .ToUpper().IndexOf("CONTENT-LENGTH");

//                    int content_length = 0;

//                    if (start > 0)
//                    {

//                        string temp = header.Substring(start, header.Length - start);

//                        string[] sArry = Regex.Split(temp, "\r\n");

//                        content_length = Convert.ToInt32(sArry[0].Split(':')[1]);

//                        if (content_length > 0)
//                        {

//                            byte[] bytes = new byte[content_length];

//                            if (sK.Receive(bytes) > 0)
//                            {

//                                return bytes;

//                            }

//                        }

//                    }

//                    else
//                    {

//                        //不存在Content-Length协议头

//                        return ParseResponse(sK);

//                    }

//                }

//                else
//                {

//                    return Encoding.Default.GetBytes(header);

//                }

//            }

//            else
//            {

//                source.Cancel();  //超时的话，别忘记取消任务哦

//            }

//            return null;

//        }



//        /// <summary>

//        ///  读取协议头

//        /// </summary>

//        /// <param name="args"></param>

//        /// <returns></returns>

//        static string ReadHeaderProcess(object args)
//        {

//            Socket sK = (Socket)args;

//            StringBuilder bulider = new StringBuilder();

//            while (true)
//            {

//                byte[] buff = new byte[1];

//                int read = sK.Receive(buff, SocketFlags.None);

//                if (read > 0)
//                {

//                    bulider.Append((char)buff[0]);

//                }

//                string temp = bulider.ToString();

//                if (temp.Contains("\r\n\r\n"))
//                {

//                    break;

//                }

//            }

//            return bulider.ToString();

//        }



//        /// <summary>

//        /// 注意：此函数可能产生死循环

//        /// </summary>

//        /// <param name="ssl"></param>

//        /// <returns></returns>

//        static byte[] ParseResponse(Socket sK)
//        {

//            ArrayList array = new ArrayList();

//            StringBuilder bulider = new StringBuilder();

//            int length = 0;

//            while (true)
//            {

//                byte[] buff = new byte[1024];

//                int len = sK.Receive(buff);

//                if (len > 0)
//                {

//                    length += len;

//                    byte[] reads = new byte[len];

//                    Array.Copy(buff, 0, reads, 0, len);

//                    array.Add(reads);

//                    bulider.Append(Encoding.Default.GetString(reads));

//                }

//                string temp = bulider.ToString();

//                if (temp.ToUpper().Contains("</HTML>"))
//                {

//                    break;

//                }

//            }

//            byte[] bytes = new byte[length];

//            int index = 0;

//            for (int i = 0; i < array.Count; i++)
//            {

//                byte[] temp = (byte[])array[i];

//                Array.Copy(temp, 0, bytes,

//                    index, temp.Length);

//                index += temp.Length;

//            }

//            return bytes;

//        }


//        static byte[] GetResponse(Socket sK)
//        {
//            using (var ms = new MemoryStream())
//            {
//                using (BinaryWriter bw = new BinaryWriter(ms))
//                {
//                    while (true)
//                    {
//                        byte[] buff = new byte[1024];
//                        int len = sK.Receive(buff);
//                        if (len > 0)
//                        {
//                            bw.Write(buff);
//                        }
//                        else
//                        {
//                            break;
//                        }
//                    }
//                    return bw.BaseStream.ToBytes();
//                }
//            }
//        }


//        private static string GetHead(Socket sk)
//        {
//            List<byte> list = new List<byte>();
//            byte[] bytes = new byte[1];
//            while (sk.Receive(bytes, 0, 1, SocketFlags.None) > 0)
//            {
//                list.Add(bytes[0]); //EndsWith("\r\n\r\n")
//                int count = list.Count;
//                if (bytes[0] == '\n' && count >= 4
//                    && list[count - 1] == '\n'
//                    && list[count - 2] == '\r'
//                    && list[count - 3] == '\n'
//                    && list[count - 4] == '\r'
//                    )
//                    break;
//            }
//            return Encoding.ASCII.GetString(list.ToArray());
//            //MatchCollection matches = new Regex("[^\r\n]+").Matches(Header.TrimEnd('\r', '\n'));
//            //for (int n = 1; n < matches.Count; n++)
//            //{
//            //    string[] strItem = matches[n].Value.Split(new char[] { ':' }, 2);
//            //    if (strItem.Length > 0)
//            //        Headers[strItem[0].Trim()] = strItem[1].Trim();
//            //}
//            //// check if the page should be transfered to another location
//            //if (matches.Count > 0 && (
//            //    matches[0].Value.IndexOf(" 302 ") != -1 ||
//            //    matches[0].Value.IndexOf(" 301 ") != -1))
//            //    // check if the new location is sent in the "location" header
//            //    if (Headers["Location"] != null)
//            //    {
//            //        try { ResponseUri = new Uri(Headers["Location"]); }
//            //        catch { ResponseUri = new Uri(ResponseUri, Headers["Location"]); }
//            //    }
//            //ContentType = Headers["Content-Type"];
//            //if (Headers["Content-Length"] != null)
//            //    ContentLength = int.Parse(Headers["Content-Length"]);
//            //KeepAlive = (Headers["Connection"] != null && Headers["Connection"].ToLower() == "keep-alive") ||
//            //            (Headers["Proxy-Connection"] != null && Headers["Proxy-Connection"].ToLower() == "keep-alive");
//        }

//        private static string GetHtml(Socket sk, RequestParameter rp)
//        {
//            byte[] recvBuffer = new byte[10240];
//            using (var ms = new MemoryStream())
//            {
//                using (var bw = new BinaryWriter(ms))
//                {
//                    int nBytes;
//                    while ((nBytes = sk.Receive(recvBuffer, 0, 10240, SocketFlags.None)) > 0)
//                    {
//                        bw.Write(recvBuffer, 0, nBytes);
//                    }
//                }
//                return rp.Encoding.GetString(ms.ToArray());
//            }
//        }

//        #endregion

//        #region  Helper

//        static byte[] ParseHttpArgs(HttpMethod method, HttpArgs args)
//        {

//            StringBuilder bulider = new StringBuilder();

//            if (method.Equals(HttpMethod.POST))
//            {
//                bulider.AppendLine(string.Format("POST {0} HTTP/1.1", args.Url));
//                bulider.AppendLine("Content-Type: application/x-www-form-urlencoded");
//            }
//            else
//            {
//                bulider.AppendLine(string.Format("GET {0} HTTP/1.1", args.Url));
//            }

//            bulider.AppendLine(string.Format("Host: {0}", args.Host));

//            bulider.AppendLine("User-Agent: Mozilla/5.0 (Windows NT 6.1; IE 9.0)");

//            if (!string.IsNullOrEmpty(args.Referer))

//                bulider.AppendLine(string.Format("Referer: {0}",

//                    args.Referer));

//            bulider.AppendLine("Connection: keep-alive");

//            bulider.AppendLine(string.Format("Accept: {0}",

//                args.Accept));

//            bulider.AppendLine(string.Format("Cookie: {0}",

//                args.Cookie));

//            if (method.Equals(HttpMethod.POST))
//            {

//                bulider.AppendLine(string.Format("Content-Length: {0}\r\n",

//                   Encoding.Default.GetBytes(args.Body).Length));

//                bulider.Append(args.Body);

//            }

//            else
//            {

//                bulider.Append("\r\n");

//            }

//            string header = bulider.ToString();

//            return Encoding.Default.GetBytes(header);
//        }

//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="rp"></param>
//        /// <returns></returns>
//        static byte[] ParseHttpArgs(RequestParameter rp)
//        {
//            Uri uri = new Uri(rp.Url);
//            StringBuilder bulider = new StringBuilder();
//            if (rp.Method == "POST")
//            {
//                bulider.AppendLine(string.Format("POST {0} HTTP/1.0", uri.PathAndQuery));
//                bulider.AppendLine("Content-Type: application/x-www-form-urlencoded");
//            }
//            else
//            {
//                bulider.AppendLine(string.Format("GET {0} HTTP/1.0", uri.PathAndQuery));
//            }

//            bulider.AppendLine(string.Format("Host: {0}", uri.Host));
//            bulider.AppendLine("User-Agent: Mozilla/5.0 (Windows NT 6.1; IE 9.0)");
//            if (rp.Referer.IsNotBlank())
//                bulider.AppendLine(string.Format("Referer: {0}", rp.Referer));
//            bulider.AppendLine("Connection: keep-alive");

//            if (rp.Accept.IsNotBlank())
//                bulider.AppendLine(string.Format("Accept: {0}", rp.Accept));

//            //if (rp.InitCookie && rp.CookieCollection != null)
//            //{
//            //    rp.CookieCollection[0].
//            //    bulider.AppendLine(string.Format("Cookie: {0}", args.Cookie));
//            //}
//            if (rp.Method == "POST")
//            {
//                bulider.AppendLine(string.Format("Content-Length: {0}\r\n", Encoding.Default.GetBytes(rp.PostDataString).Length));
//                bulider.Append(rp.PostDataString);
//            }
//            else
//            {
//                bulider.Append("\r\n");
//            }
//            string header = bulider.ToString();
//            return Encoding.ASCII.GetBytes(header);
//        }

//        #endregion


//        #region core
//        /// <summary>
//        /// 获取内容
//        /// </summary>
//        /// <param name="rp">RequestParameter</param>
//        /// <returns></returns>
//        public static bool GetHtml(RequestParameter rp)
//        {
//            Uri uri = new Uri(rp.Url);
//            using (Socket sK = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
//            {
//                try
//                {
//                    IPHostEntry ipHostEntry = Dns.Resolve(uri.Host);
//                    IPEndPoint ipEndPoint = new IPEndPoint(ipHostEntry.AddressList[0], uri.Port);
//                    sK.Connect(ipEndPoint);
//                    if (sK.Connected)
//                    {
//                        byte[] buff = ParseHttpArgs(rp);
//                        if (sK.Send(buff) > 0)
//                        {
//                            byte[] re = new byte[1000000];
//                            sK.Receive(re);
//                            Console.WriteLine(Encoding.ASCII.GetString(re));

//                            var head = GetHead(sK);
//                            Console.WriteLine(head);
//                            var html = GetHtml(sK, rp);
//                            rp.Text = html;
//                        }
//                    }
//                }
//                catch (Exception ex)
//                {
//                    LogHelper.Error("SocketCrawler error", ex);
//                }
//            }
//            return false;
//        }
//        #endregion

//    }

//}
